From: Philip Withnall Date: Mon, 2 Oct 2017 17:04:37 +0000 (+0100) Subject: lib/bloom: Add some missing preconditions on n_bytes X-Git-Tag: archive/raspbian/2022.1-3+rpi1~1^2~4^2~30^2~91 X-Git-Url: https://dgit.raspbian.org/%22http://www.example.com/cgi/success//%22http:/www.example.com/cgi/success/?a=commitdiff_plain;h=030e3efbc41f1f4f8d3fd2c64da235869b0f6f0b;p=ostree.git lib/bloom: Add some missing preconditions on n_bytes These shouldn’t change the bloom filter’s behaviour at all, but make it a bit more obvious what the programmatical limitations are on the sizes it can deal with. In reality, those sizes should never be reached because they won’t fit in a DNS-SD record. Signed-off-by: Philip Withnall Closes: #1239 Approved by: cgwalters --- diff --git a/src/libostree/ostree-bloom.c b/src/libostree/ostree-bloom.c index 9bd2ad28..c6de2640 100644 --- a/src/libostree/ostree-bloom.c +++ b/src/libostree/ostree-bloom.c @@ -76,7 +76,7 @@ struct _OstreeBloom { guint ref_count; - gsize n_bytes; + gsize n_bytes; /* 0 < n_bytes <= G_MAXSIZE / 8 */ gboolean is_mutable; /* determines which of [im]mutable_bytes is accessed */ union { @@ -117,6 +117,7 @@ ostree_bloom_new (gsize n_bytes, g_autoptr(OstreeBloom) bloom = NULL; g_return_val_if_fail (n_bytes > 0, NULL); + g_return_val_if_fail (n_bytes <= G_MAXSIZE / 8, NULL); g_return_val_if_fail (k > 0, NULL); g_return_val_if_fail (hash_func != NULL, NULL); @@ -159,6 +160,7 @@ ostree_bloom_new_from_bytes (GBytes *bytes, g_return_val_if_fail (bytes != NULL, NULL); g_return_val_if_fail (g_bytes_get_size (bytes) > 0, NULL); + g_return_val_if_fail (g_bytes_get_size (bytes) <= G_MAXSIZE / 8, NULL); g_return_val_if_fail (k > 0, NULL); g_return_val_if_fail (hash_func != NULL, NULL);